<% content_for :page_title do %>
  <%= Spree.t(:loyalty_points) %>
<% end %>

<% content_for :page_actions do %>
  <%= button_link_to Spree.t(:back_to_users_list), spree.admin_users_path, class: 'btn btn-primary', icon: 'chevron-left' %>
<% end %>

<%= render partial: 'spree/shared/error_messages', locals: { target: @loyalty_points_transaction.user } %>
<%= render partial: 'spree/shared/error_messages', locals: { target: @loyalty_points_transaction } %>

<div id='loyalty-points-order-transactions'></div>

<%= form_for @loyalty_points_transaction, as: :loyalty_points_transaction, url: spree.admin_user_loyalty_points_path(@user), class: 'form' do |f| %>
  <fieldset data-hook="update_loyalty_points">

    <legend align="center"><%= Spree.t(:update_loyalty_points) %></legend>

    <div data-hook="update_loyalty_points_attrs" class="row">

      <div class="col-md-4 form-group">
        <%= f.field_container :loyalty_points do %>
          <%= f.label :loyalty_points, Spree.t(:loyalty_points) %> <span class="required">*</span><br />
          <%= f.text_field :loyalty_points, class: 'fullwidth title form-control' %>
          <%= f.error_message_on :loyalty_points %>
        <% end %>
      </div>

      <div class="field col-md-4">
          <%= f.label :type, Spree.t(:transaction_type) %> <span class="required">*</span><br />
          <%= f.select :type, options_for_select(Spree::LoyaltyPointsTransaction::CLASS_TO_TRANSACTION_TYPE.invert), {}, class: 'select2 fullwidth' %>
          <%= f.error_message_on :type %>
      </div>

        <div class="field col-md-4">
          <%= label_tag nil, Spree.t(:order) %>
          <%= f.select :source_id, @user.orders.collect {|o| [o.number, o.id]}, {include_blank: true}, class: 'select2 fullwidth', :"data-transactions-link" => spree.admin_user_loyalty_points_path(@user) %>
          <%= f.hidden_field :source_type, { value: 'Spree::Order' } %>
        </div>

    </div>

    <div data-hook="comment_row" class="row">

      <div class="col-md-4 form-group">
        <%= f.field_container :comment do %>
          <%= f.label :comment, Spree.t(:comment) %> <span class="required">*</span><br />
          <%= f.text_area :comment, class: 'fullwidth form-control', rows: '3' %>
          <%= f.error_message_on :comment %>
        <% end %>
      </div>

    </div>

    <div class="form-buttons filter-actions actions" data-hook="buttons">
      <%= button Spree.t('actions.update'), 'ok' %>
      <span class="or"><%= Spree.t(:or) %></span>
      <%= link_to_with_icon 'remove', Spree.t('actions.cancel'), spree.admin_users_path, class: 'btn btn-primary' %>
    </div>

  </fieldset>
<% end %>
